from django.db import models
from management.models import BaseModel


# 员工表
class StaffModel(BaseModel):
    name = models.CharField(verbose_name="姓名", max_length=52)
    account = models.CharField(verbose_name="账号", max_length=228, default="")
    # avatar_url = models.CharField(verbose_name="用户头像", max_length=256, null=True, blank=True)
    mobile = models.CharField(verbose_name='手机号', max_length=11)
    password = models.CharField(verbose_name="密码", max_length=256)
    email = models.CharField(verbose_name="邮箱", max_length=256, null=True, blank=True)
    birthday = models.DateField(verbose_name="生日", null=True, blank=True, default="2022-01-01")
    region = models.CharField(verbose_name="地区", max_length=128, default="未知")
    position_id = models.BigIntegerField(verbose_name="职位id")
    role_id = models.BigIntegerField(verbose_name="角色id")
    class Meta():
        db_table="staff_tb"
        verbose_name = "员工表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 邮件表
class EmailModel(BaseModel):
    title = models.CharField(verbose_name="标题", max_length=128)
    content = models.CharField(verbose_name="内容", max_length=512)
    class Meta():
        db_table = "email_tb"
        verbose_name = "邮件表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"邮件 {self.title}"


# 收发邮件表
class SendToEmailModel(BaseModel):
    send_staff_id = models.BigIntegerField(verbose_name="发送人", null=True, blank=True)
    to_staff_id = models.BigIntegerField(verbose_name="收件人", null=True, blank=True)
    email_id = models.BigIntegerField(verbose_name="邮件")
    class Meta():
        db_table = "send_to_email_tb"
        verbose_name = "收发邮件表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"收件人 {self.to_staff_id}"


# 邮件附件
class EmailAppendixModel(BaseModel):
    email_id = models.BigIntegerField(verbose_name="所属邮件")
    appendix_url = models.CharField(verbose_name="附件地址", max_length=256)
    class Meta():
        db_table = "email_appendix_tb"
        verbose_name = "邮件附件表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"所属邮件 {self.email_id}"


# 工资条
class PayrollModel(BaseModel):
    staff_id = models.BigIntegerField(verbose_name="所属员工")
    attendance = models.IntegerField(verbose_name="出勤")
    absenteeism = models.IntegerField(verbose_name="旷工")
    leave = models.IntegerField(verbose_name="请假")
    base_salary = models.DecimalField(verbose_name="基本工资", max_digits=9, decimal_places=2)
    position_salary = models.DecimalField(verbose_name="岗位工资", max_digits=9, decimal_places=2)

    class Meta():
        db_table = "payroll_tb"
        verbose_name = "工资条表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"所属员工 {self.staff_id}"


# 材料管理
class MaterialsModel(BaseModel):
    name = models.CharField(verbose_name="名称", max_length=20)
    url = models.CharField(verbose_name="地址", max_length=256)
    class Meta():
        db_table="materials_tb"
        verbose_name = "材料表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name